package org.xtext.runtime.term;

import java.util.Map;

import org.xtext.runtime.formula.IFormula;
import org.xtext.runtime.type.IType;
import org.xtext.runtime.type.Type;
import org.xtext.runtime.util.Bindings;
import org.xtext.runtime.util.ILogicVisitor;


public class CountTerm implements ITerm {
	private IFormula formula;
	
	public CountTerm(IFormula formula) {
		this.formula = formula;
//		System.out.println("setting type: " + type);
	}
	
	@Override
	public IType type() {
		return Type.integerType;
	}

	@Override
	public ITerm copy() {
		return new CountTerm(formula.copy());
	}

	@Override
	public Object value() {
		throw new UnsupportedOperationException();
	}

	public String toString() {
		return "count(" + formula + ")";
	}

	@Override
	public CountTerm copy(Map<String, Variable> vars) {
		return new CountTerm(formula.copy(vars));
	}

	@Override
	public CountTerm apply(Bindings bindings) {
		formula.apply(bindings);
		return this;
	}


	@Override
	public boolean hasFreeVariables() {
		// returns false event if the inner formula has variables...
		return false;
	}

	@Override
	public Object accept(ILogicVisitor visitor) {
		return visitor.visit(this);
	}

	public IFormula formula() {
		return formula;
	}
}
